<?php // labs.php -- Displays open/closed labs

// All of our Lab objects are stored in 'objects.php'

include("objects.php");

// Create an array to store the fact that a lab is open

$openlabs = array ();

print "<div class=\"main image\"> <!-- Start MAIN LABS div -->\n";

foreach($lab_array as $lab) {
	if ($lab->get_open_status()) {
		print "
	<div class=\"lab_open";

	// Have to take care of the labs that have a different image

	if ($lab->get_string_rep() == 'helpdesk' || $lab->get_string_rep() == 'av' || $lab->get_string_rep() == 'mathlan') {
		print " {$lab->get_string_rep()}_open_image";
	}

	print " {$lab->get_string_rep()}\">
	<div class=\"popup_closed\">
	<div class=\"inside\">
	<div class=\"text\"><p><a href=\"" . $lab->get_url() . "\">" . $lab->get_name() . "</a>";

	/* For the group of Noyce labs, we need to print "are" as opposed to the usual "is"
	(Naturally, this should follow for any group of labs for which we use one icon) */

	$lab_name = $lab->get_name();
	if ($lab_name == 'Noyce 2401 and 2402' || $lab_name == 'Gencomp and Inslab') {
		print " are ";
	}
	else {
		print " is ";
	}
	
	/* Check to see if a lab is always open */

	$always_open_status = $lab->get_always_open_status();
	if ($always_open_status) {
		print "always ";
	}

		print "open</p>
	</div> <!-- End \"text\" div -->
	</div> <!-- End \"inside\" div -->
	</div> <!-- End \"popup\" div -->
	</div> <!-- End \"open lab\" div -->\n";

		// Adds data to an existing array
		$openlabs[] = $lab->get_name();
		}
	else
		{
		print "
	<div class=\"lab_closed {$lab->get_string_rep()}";

	// Have to take care of the labs that have a different image

	if ($lab->get_string_rep() == 'helpdesk' || $lab->get_string_rep() == 'av' || $lab->get_string_rep() == 'mathlan') {
		print " {$lab->get_string_rep()}_closed_image";
	}

	print "\">
	<div class=\"popup_closed\">
	<div class=\"inside\">
	<div class=\"text\"><p>" . $lab->get_name();

	$lab_name = $lab->get_name();
        if ($lab_name == 'Noyce 2401 and 2402' || $lab_name == 'Gencomp and Inslab') {
                print " are ";
        }
        else {
 		print " is "; 
	}

	print "closed";

	/* If it's a break, we want to print why the lab is closed */
	if (HOLIDAY) {
		print " for the break";
	}

	print "</p>
	</div> <!-- End \"text\" div -->
	</div> <!-- End \"inside\" div -->
	</div> <!-- End \"popup\" div -->
	</div> <!-- End \"closed lab\" div -->\n";
		}
	}

print "\n</div> <!-- End MAIN LABS div -->\n";

// Now, find and print information about the open labs

	// If it's a break, no labs are technically open
	if (HOLIDAY) {
		print "<p>Unless otherwise noted, lab facilities are closed for the break</p>\n";
	}

	// Otherwise, find and print open labs
	else {
		$length = count($openlabs);
		$small_labs = array_slice($openlabs, 0, ($length - 1));
		$string_labs = implode(', ', $small_labs);
	
		// Replace every instance of "The" with "the"
		$string_labs = ereg_replace('The', 'the', $string_labs);     
	
		$last_int = ($length - 1);
		$labs = "Currently, $string_labs and $openlabs[$last_int] are open";		
		print "\n<p class=\"obl\">$labs</p>\n";				  
        	print '<p class="obl">Lab times and openings are subject to change</p>';
	}

?>
